//获取应用实例
const app = getApp()
Page({
  data:{
    order:{},
    role:"normal"
  },
  onLoad: function (option) {
    var openId = app.globalData.openId;
    var account=wx.getStorageSync(openId);
    this.setData({
      role: account.role
    });
    const order=JSON.parse(option.order);
    this.setData({
      order:order
    });
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var order=this.data.order;
    order.transferDate = e.detail.value;
    this.setData({
      order: order
    })
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    const order = e.detail.value;
    order.total = (order.price * order.weight).toFixed(2);
    order.type = 0;
    order.updater = app.globalData.openId;
    order.orderId = this.data.order.orderId;
    wx.request({
      url: app.globalData.baseUrl + 'order/updateOrder',
      data: order,
      method: "POST",
      success: function (res) {
        if (res.data.code == 0) {
          wx.navigateBack({
            complete: function () {
              wx.showToast({
                title: "修改支出成功",
                icon: "success"
              });
            }
          });
        } else {
          wx.showToast({
            title: "修改支出失败",
            icon: "fail"
          })
        }
      }
    });
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }
});